-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove HeaderString::c_str() and migrate callers to getStringView() #6564
Conversation
Signed-off-by: Dan Noé <[email protected]>
Signed-off-by: Dan Noé <[email protected]>
This doesn't work, of course. Signed-off-by: Dan Noé <[email protected]>
The old code in the section that failed to build in release and coverage builds is this:
I'll admit to being a little confused about what it means to assign a It's also unclear why the other configurations didn't fail to build. |
@dnoe Yeah it'll create a temporary and its lifetime is extended (https://abseil.io/tips/107) |
Signed-off-by: Dan Noé <[email protected]>
Now that we use string_view, we can use range-based-for and make the loop more readable. Signed-off-by: Dan Noé <[email protected]>
Looks great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I only reviewed until source/common though.
source/common/grpc/common.cc
Outdated
.inc(); | ||
uint64_t grpc_status_code; | ||
std::string grpc_status_string(grpc_status->value().getStringView()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider use absl::SimpleAtoi
instead of atoull (or implement StringUtil::atoull with absl::SimpleAtoi) so we can avoid this string allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea - I will create an issue to follow up by either implementing StringUtil::atoull
with absl::SimpleAtoi
or converting call sites. I think there was only one spot in the code I found where the return value of StringUtil::atoull
(which is C-style) was used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks this is absolutely awesome. Huge props for slogging through this and I love seeing the tech debt disappear.
I mainly have comments around adding TODOs for all the other places we can get rid of string copies. We have the opportunity here to speed things up in a non-trivial way as part of these changes which is great.
/wait
source/common/grpc/common.cc
Outdated
.inc(); | ||
uint64_t grpc_status_code; | ||
std::string grpc_status_string(grpc_status->value().getStringView()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: const here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, though my eyes glaze over reading this diff so please let me know if I missed another :)
source/common/http/header_utility.cc
Outdated
@@ -87,27 +87,29 @@ bool HeaderUtility::matchHeaders(const Http::HeaderMap& request_headers, | |||
} | |||
|
|||
bool match; | |||
absl::string_view header_view = header->value().getStringView(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to make this copy? If so can we TODO removing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is just for readability reasons since it gets pretty busy seeing header->value().getStringView()
repeated especially when std::regex_match
takes begin()
and end()
. The copy of a string_view should be only slightly worse than a pointer. I've marked it as const
, which may prevent the copy entirely.
I'm happy to remove it too if you'd like, but I think it makes this much more readable rather than repeating the header->value().getStringView()
.
@@ -66,7 +66,7 @@ Decision HttpTracerUtility::isTracing(const StreamInfo::StreamInfo& stream_info, | |||
|
|||
// TODO PERF: Avoid copy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you fixed this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I did now that isTraceableUuid
takes string_view
rather than std::string
. Removing the comment, taking the credit (I don't see an existing issue for this, if there is feel free to close it).
Signed-off-by: Dan Noé <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice this is so awesome. Looking forward to the followup cleanups. A few more comments from another pass. Thank you!
/wait
Use lua_pushlstring to avoid std::string construction. Signed-off-by: Dan Noé <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! @lizan do you want to do any additional review?
Signed-off-by: Dan Noé <[email protected]>
…c_str_by_the_c_shore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnoe can you merge master again?
…c_str_by_the_c_shore Signed-off-by: Dan Noe <[email protected]>
Master merge conflicts addressed. |
Remove the
HeaderString::c_str()
API, and migrate all callers of it togetStringView()
andstring_view
style usage (ie,absl::string_view::find
instead of C style comparisons) wherever appropriate.Risk Level: Medium. No logic changes intended, but this is delicate and risky code and a large portion of the code base was touched.
Testing:
bazel test //test/...
Docs Changes: None
Release Notes: None
Fixes #6494